<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Send to friend form
 *
 * @see Mage_Sendfriend_Block_Index
 */
?>
<div class="padder">
<script type="text/javascript">
/*<![CDATA[*/
    i=0;
    var recipCount  = 1;
    var maxRecip    = <?php echo $this->getMaxRecipients() ?>;
    function remove_recipient(i){
        $('recipients_name'+i).up(2).remove();
        recipCount--;
        if(recipCount<maxRecip && maxRecip != 0) {
            $('add_recipient_button').show();
            $('max_recipient_message').hide();
        }
        return false;
    }

    function add_recipient(){
        ul = $('recipients_options');
        var li_mail = Element.extend(document.createElement("LI"));
        li_mail.addClassName('addElement');
        li_mail.innerHTML = '<div align="right"><a href="delete_email" onclick="remove_recipient('+i+');return false"><img src="<?php echo $this->getSkinUrl('images/list_remove_btn.gif') ?>" alt="<?php echo $this->__('Remove Email') ?>" \/><\/a><\/div>'
        li_mail.innerHTML += '<div class="input-box"><label for="recipients_name"><?php echo $this->__('Name:') ?> <span class="required">*<\/span><\/label><br /><div style="width:250px"><input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name'+i+'" style="width:250px;" \/><\/div><\/div>';
        li_mail.innerHTML += '<div class="input-box"><label for="recipients_email"><?php echo $this->__('Email Address:') ?><span class="required">*<\/span><\/label><br /><div style="width:250px"><input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email'+i+'" type="text" class="input-text required-entry validate-email" style="width:250px;" \/><\/div><\/div>';
        i++;
        recipCount++;
        if(recipCount>=maxRecip && maxRecip != 0) {
            $('add_recipient_button').hide();
            $('max_recipient_message').show();
        }

        ul.appendChild(li_mail);
    }
/*]]>*/
</script>

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-head">
    <h3><?php echo $this->__('Email to a Friend') ?></h3>
</div>
<form action="<?php echo $this->getUrl('*/*/sendmail',array('id'=>$this->getProductId())) ?>" method="post" id="product_sendtofriend_form">

                <fieldset class="group-select">
                    <div class="head-alt2">
                        <h4 class="title"><?php echo $this->__('Sender:') ?></h4>
                    </div>
                     <ul id="sender_options">
                           <li>
                                <div class="input-box">
                                    <label for="sender_name"><?php echo $this->__('Name:') ?> <span class="required">*</span></label><br />
                                    <input name="sender[name]" value="<?php echo $this->htmlEscape($this->getUserName()) ?>" title="<?php echo $this->__('Name') ?>" id="sender_name" type="text" class="input-text required-entry"/>
                                </div>
                                <div class="input-box">
                                   <label for="sender_email"><?php echo $this->__('Email:') ?> <span class="required">*</span></label><br />
                                  <input name="sender[email]" value="<?php echo $this->htmlEscape($this->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" id="sender_email" type="text" class="input-text required-entry validate-email"/>
                                </div>
                            </li>
                            <li>
                                <label for="sender_message"><?php echo $this->__('Message:') ?> <span class="required">*</span></label><br />
                                <textarea name="sender[message]" class="input-text required-entry" id="sender_message" rows="3" cols="3" style="height:100px"><?php echo $this->htmlEscape($this->getFormData()->getData('sender/message'))?></textarea>
                            </li>
                     </ul>

                   <br />
                    <div class="head-alt2">
                        <h4 class="title"><?php echo $this->__('Recipient:') ?></h4>
                    </div>
                    <ul id="recipients_options">
                            <li>
                                <div class="input-box">
                                    <label for="recipients_name"><?php echo $this->__('Name:') ?> <span class="required">*</span></label><br />
                                    <input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name"/>
                                </div>
                                <div class="input-box">
                                    <label for="recipients_email"><?php echo $this->__('Email Address:') ?> <span class="required">*</span></label><br />
                                    <input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email" type="text" class="input-text required-entry validate-email"/>
                                </div>
                            </li>
                    </ul>
                    <div id="max_recipient_message" style="display:none">
                    <?php if ($this->getMaxRecipients()): ?>
                      <?php echo $this->__('Maximum %d email addresses allowed.', $this->getMaxRecipients()) ?>
                    <?php endif; ?>
                    </div>
                    <?php if (1 < $this->getMaxRecipients()): ?>
                        <div id="add_recipient_button">
                            <a href="#" onclick="add_recipient();"><img src="<?php echo $this->getSkinUrl('images/btn_add_recipient.gif') ?>" alt="<?php echo $this->__('Add Recipient') ?>"/></a>
                        </div>
                    <?php endif; ?>
            <div class="clear"></div>
            </fieldset>
        <div class="button-set">
            <input type="image" src="<?php echo $this->getSkinUrl('images/btn_send_email.gif') ?>" alt="<?php echo $this->__('Send email') ?>"/>
        </div>
</form>
<script type="text/javascript">
    var productSendtofriendForm = new VarienForm('product_sendtofriend_form');
    productSendtofriendForm.submit = function() {
        if(this.validator.validate()) {
            this.form.submit();
        }
    }.bind(productSendtofriendForm);
</script>
</div>